<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="edu.ynu.onlinesqltool.model.*"%>
<jsp:useBean id="records" type="java.util.ArrayList" scope="request"></jsp:useBean>
<%!int pageNo,total; String sql; %>
<%
total=Integer.parseInt(request.getParameter("total"));
pageNo=Integer.parseInt(request.getParameter("pageNo"));
sql=request.getParameter("sql");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>Records</title>
    
     <script type="text/javascript">
    <!--
    function iframeAutoFit()
    {
        var ex;
        try
        {
            if(window!=parent)
            {
                var a = parent.document.getElementsByTagName("iframe");
                
                for(var i=0; i<a.length; i++) //author:meizz
                {
                    if(a[i].contentWindow==window)
                    {
                        var h1=0, h2=0, h3=0, h4=0;
                        if(document.documentElement&&document.documentElement.scrollHeight)
                        {
                            h1 = document.documentElement.scrollHeight;
                            h3 = document.documentElement.scrollWidth;
                        }
                        if(document.body) h2=document.body.scrollHeight;h4=document.body.scrollWidth;
                        

                        var h=Math.max(h1, h2);
                        var h0=Math.max(h3,h4);
                       
                        a[i].style.height = h +"px";
                        a[i].style.width = h0 + "px";
                    }
                }
            }
        }
        catch (ex){}
    }
    
    if(document.attachEvent)
    {
        window.attachEvent("onload",  iframeAutoFit);
        window.attachEvent("onresize",  iframeAutoFit);
    }
    else
    {
        window.addEventListener('load',  iframeAutoFit,  false);
        window.addEventListener('resize',  iframeAutoFit,  false);
    }
    function checkPageNo()
    {
        var n=document.getElementById('pageNo').value;
        var s=<%=(int)Math.ceil(total/5.0)%>;
        if(n>s)
        {
           n=s;
        }
        location.href="excuteSQL.do?action=execute&sql=<%=sql%>&pageNo="+n;
    }
    //-->
    </script>
  </head>
  
  <body leftmargin="0">
  <%
    if(records.size()<1){
      out.println("没有相应的记录！");
    }
    else{
      out.println("<div style='font-size:12px'>共"+total+"条记录</div>");
  %>
    <table width="200" border="1" cellspacing="0" bordercolor="#B8B8B8">
  <tr>
  <% 
  List record=(List)records.get(0);
  if(record.size()>1){
  for(int i=0;i<record.size();i++){
    DataItem dataItem=(DataItem)record.get(i);
    out.println("<td>"+dataItem.getColumnName()+"&nbsp;</td>");
  }}
  %>
  </tr>
  <% 
  for(int i=0;i<records.size();i++){
    out.println("<tr>");
    List _record=(List)records.get(i);
    for(int j=0;j<_record.size();j++){
      DataItem _dataItem=(DataItem)_record.get(j);
      out.println("<td>"+_dataItem.getColumnValue()+"&nbsp;</td>");
    }
    out.println("</tr>");
  }
  %>
</table>
<%} %>
<p style="font-size:12px">
<% 
if(pageNo-1==0){
  out.println("第一页");
}
else{
%>
<a href="excuteSQL.do?action=execute&sql=<%=sql%>&pageNo=<%=pageNo-1%>">上一页</a>
<%}
if(pageNo*5>=total){
  out.println("最后一页");
}
else{
%>
<a href="excuteSQL.do?action=execute&sql=<%=sql%>&pageNo=<%=pageNo+1%>">下一页</a>
<%} %>
共<%=(int)Math.ceil(total/5.0)%>页  
到第<input id="pageNo" name="pageNo" type="text" style="height:20px;width:30px" value="<%=pageNo%>"/>页
<input type="button" value="确定" style="height:20px" onclick="checkPageNo()"></input>
</p>
  </body>
</html>
